package com.example.application8_2;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;

import androidx.annotation.Nullable;

import static java.sql.Types.INTEGER;
import static org.xmlpull.v1.XmlPullParser.TEXT;
/*

        工具类，单例模式：构造函数私有化，对外提供函数
 */
public class DbHelper extends SQLiteOpenHelper {

//    private static SQLiteOpenHelper mInstance;
//    public static synchronized SQLiteOpenHelper getmInstance(View.OnClickListener context){
//        if (mInstance == null){
//            mInstance = new DbHelper((Context) context,"sqlite.db",null,1);
//        }
//        return mInstance;
//    }

    private Context context;
    public DbHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, "sqlite.db",null,1);
        this.context = context;
    }




    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table users (_id integer primary key autoincrement,"+"username text , age integer)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists users");
        onCreate(db);
    }
}
